package com.thesis.teacher.controller;

import com.alibaba.fastjson.JSONObject;
import com.thesis.manage.common.constant.YesOrNoEnum;
import com.thesis.manage.common.utils.Result;
import com.thesis.manage.domain.StudentTeacher;
import com.thesis.manage.domain.Teacher;
import com.thesis.manage.service.StudentTeacherService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author php
 * @date 2018/3/16
 */
@RequestMapping("/studentTeacher")
@RestController
public class StudentTeacherController extends BaseController {

    @Resource
    private StudentTeacherService studentTeacherService;

    /**
     * 通过教师id查询指导学生列表
     */
    @GetMapping("/list")
    public Map<String, Object> findAllByTeacherId() {
        return buildMessage(() -> {
            Result result = getUser();
            Teacher teacher = JSONObject.parseObject(result.getData().toString(), Teacher.class);
            StudentTeacher studentTeacher = new StudentTeacher();
            studentTeacher.setTeacherNumber(teacher.getTeacherNumber());
            // 设置学生和老师的状态 no代表还未指导结束
            studentTeacher.setStatus(YesOrNoEnum.NO.getValue());
            return studentTeacherService.findAllByTeacherId(studentTeacher);
        });
    }

    /**
     * 通过学生id查询学生论文相关信息
     *
     * @param id 学生id
     */
    @GetMapping("/{id}/thesis")
    public Map<String, Object> findStudentThesisByStudentId(@PathVariable Long id) {
        return buildMessage(() -> studentTeacherService.findStudentThesisByStudentId(id));
    }
}
